/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.agi.util.sound;

import br.com.agi.util.geradordados.GeradorByte;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;

/**
 *
 * @author Renato
 */
public class Player {
    private GeradorByte gerador;
    private AudioFormat audioFormat;
    private SourceDataLine source;
    public Player(GeradorByte gerador, AudioFormat audioFormat) throws LineUnavailableException{      
        BuscadorDeFalantes buscador=new BuscadorDeFalantes(audioFormat);
        source=buscador.getLine();
        this.gerador=gerador;
        this.audioFormat=audioFormat;
    }
    
    public void play() throws LineUnavailableException{
        byte[] buf;
        buf=gerador.createData();
        source.open();
        source.start();
        source.write(buf, 0, (int)audioFormat.getFrameRate());
        source.stop(); 
    }
    
    
}
